
<?php
include '../base/validateAgentLogin.php';
include '../class/MMysql.php';

$employee_id= $_GET['employee_id'];

$mysql = new MMysql();

$employee = $mysql
    ->where(array('employee_id'=>$employee_id))
    ->select('employees');
?>

<?php
include '../base/layout.php';
?>

<style>
    .magin_left{
        margin-top: 20px;
        margin-left: 50px;
    }
</style>

<body>

<?php
include '../base/agentheader.php';
?>

<section style="width: 100%;">

    <?php
    include '../base/agentsidemenu.php';
    ?>

    <aside class="content">

        <?php
        echo ' <input type="hidden" id="employee_id" value="'.$employee[0]['employee_id'].'">';
        ?>


        <div style="margin-top: 65px;margin-left: 100px;">
                 <span style="font-size: 50px;">
                        Add Employees
                 </span>
        </div>

        <div style="margin-top: 50px;margin-left: 100px;">
                <span class="user_info_span">
                    Full name
                </span>
            <?php

           echo  '<input class="user_info_input" id="employee_fullname" style="width: 400px;" type="text" value="'.$employee[0]['employee_fullname'].'">'
            ?>

        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                   Email
                </span>
            <?php
            echo '<input class="user_info_input" id="employee_email" style="width: 400px;" type="text" value="'.$employee[0]['employee_email'].'">';
            ?>


        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                    Tel
                </span>

            <?php
            echo '<input class="user_info_input" id="employee_tel" style="width: 400px;" type="text" value="'.$employee[0]['employee_tel'].'">';
            ?>


        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                   Wechat
                </span>
            <?php
            echo '<input class="user_info_input" id="employee_wechat" style="width: 400px;" type="text" value="'.$employee[0]['employee_wechat'].'">';
            ?>


        </div>

        <div style="margin-top: 20px;margin-left: 100px;">
                <span class="user_info_span">
                   Address
                </span>

            <?php
            echo ' <input class="user_info_input" id="employee_address" style="width: 400px;" type="text" value="'.$employee[0]['employee_address'].'">';
            ?>


        </div>

        <div style="margin-top: 50px;margin-left: 100px;">
             <span style="font-size: 20px;color: #2B2B2B;letter-spacing: 0px;">
            Resbonsible city
        </span>

            <?php
            echo '<input type="text" id="resbonsible_city" class="form-control" style="margin-top: 20px;width: 600px;"
                   placeholder="click to input"  value="'.$employee[0]['resbonsible_city'].'">';
            ?>
        </div>

        <div style="margin-top: 40px;margin-left: 100px;">
            <button class="btn"  id="btnEdit" style="background-color: #6AAB10;color:white;width: 130px;">
                Edit
            </button>

            <button class="btn"  id="btnDelete" style="background-color: #333743;color:white;width: 130px;margin-left: 100px;">
                Delete
            </button>
        </div>
    </aside>

</section>
</body>
</html>

<script type="text/javascript">
    $(function () {
        $(".menu").height($('.content').height());

        $("#btnEdit").click(function () {

            var employee_fullname=$("#employee_fullname").val();
            var employee_email=$("#employee_email").val();
            var employee_tel=$("#employee_tel").val();
            var employee_wechat=$("#employee_wechat").val();
            var employee_address=$("#employee_address").val();
            var resbonsible_city=$("#resbonsible_city").val();


            if(employee_fullname.trim()==""){
                alert(' name is not null ');
                return;
            }
            if(employee_email.trim()==""){
                alert('email tel is not null ');
                return;
            }
            if(employee_tel.trim()==""){
                alert(' tel email is not null ');
                return;
            }
            if(employee_wechat.trim()==""){
                alert(' wechat is not null ');
                return;
            }
            if(employee_address.trim()==""){
                alert(' address  is not null ');
                return;
            }
            if(resbonsible_city.trim()==""){
                alert(' resbonsible city  is not null ');
                return;
            }
            $.ajax( {
                url: '../class/employees/employeesfunction.php',
                data:{
                    method:'edit',
                    employee_fullname : employee_fullname,
                    employee_email : employee_email,
                    employee_tel : employee_tel,
                    employee_wechat : employee_wechat,
                    employee_address : employee_address,
                    resbonsible_city : resbonsible_city,
                    employee_id:$("#employee_id").val()
                },
                type:'post',
                success:function(data) {
                    if(data==1){
                        window.wxc.xcConfirm('update success', window.wxc.xcConfirm.typeEnum.success);
                    }
                },
                beforeSend: function(){
                    //$('#warning').text('正在处理，请稍等！');
                },
                error : function() {
                    // view("异常！");
                    alert("fail");
                }
            });
        });

        $("#btnDelete").click(function(){
            var txt=  "sure delete?";
            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.confirm,{
                onOk:function(v){
                    $.ajax( {
                    url: '../class/employees/employeesfunction.php',
                    data:{
                        method:'delete',
                        employee_id:$("#employee_id").val()
                    },
                    type:'get',
                    success:function(data) {
                        if(data==1){
                            alert('delete success');
                            window.location.href='employee_list.php';
                        }
                    },
                    beforeSend: function(){
                        //$('#warning').text('正在处理，请稍等！');
                    },
                    error : function() {
                        alert("fail");
                    }
                });
                }
            });
        });
    });
</script>

